var express = require('express');
var router = express.Router();
var Classe = require('../models/classe')
const ObjectId = require('mongodb').ObjectId;



//测试数据添加
//ObjectId("5e6e54c4d146361ef4848421")
//ObjectId("5e6e54c4d146361ef4848422")
router.get('/save', function (req, res, next) {
    var uid=ObjectId('5e6e54c4d146361ef4848422');
    var myobj = [
        { name: '第一课',uid:uid},
        { name: '第二课',uid:uid}
    ];
    Classe.insertMany(myobj, function (err, result) {
        // if (err) throw err;
        if (err) {
            res.json({
                status: '1',
                msg: err.message
            })
        } else {
            res.json({
                status: '0',
                msg: '',
                result: {
                    count: result.insertedCount,
                    list: result
                }
            })
        }
    });
});



//getClassList为二级路由，
router.get('/get', function (req, res, next) {
    Classe.find({}, function (err, doc) {
        if (err) {
            res.json({
                status: '1',
                msg: err.message
            })
        } else {
            res.json({
                status: '0',
                msg: '',
                result: {
                    count: doc.length,
                    list: doc
                }
            })
        }
    })
});



module.exports = router;